//
//  DSPHomeController.swift
//  SWweibo
//
//  Created by 杜守鹏 on 15/12/26.
//  Copyright © 2015年 杜守鹏. All rights reserved.
//

import UIKit
import SVProgressHUD
class DSPHomeController: DSPVistorViewController {

    private lazy var statusListViewModel:DSPStatusListViewModel = DSPStatusListViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if userLogin == false{
            vistorView.setupInfo(nil  , labelContent: nil)
          return
        }
        setupUI()
        loadData()
       setupTableView()
    }
    //MARK:setupTableView
    func setupTableView(){
         tableView.registerClass(DSPTableViewCell.self , forCellReuseIdentifier: cellID)
        tableView.rowHeight = UITableViewAutomaticDimension
          tableView.estimatedRowHeight = 300
        tableView.separatorStyle = .None
    }
    //MARK:setupUI
    func setupUI(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendsearch", target: self, action: "didClickAddFriend")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop", target: self, action: "didClickTwoWeiMa")
    }
    //MARK:点击二维码事件
   @objc private func didClickTwoWeiMa(){
       let vc = DSPTempController()
    navigationController?.pushViewController(vc, animated: true)
    }
    //MARK:点击添加朋友案件
    @objc private func didClickAddFriend(){
        print("add")
    }
//MARK:加载数据
    private  func loadData(){
        
        statusListViewModel.loadData { (isSucceed) -> () in
            if isSucceed == true{
                self.tableView.reloadData()
            }else{
                SVProgressHUD.showErrorWithStatus("请求失败")
                
            }
        }
        
    }

    // MARK: - Table view data source

    private let cellID = "cellID"
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       
        return statusListViewModel.StatusArr?.count ?? 0
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) as! DSPTableViewCell
             cell.statusViewModel = statusListViewModel.StatusArr![indexPath.row]
        return cell
    }

}
